package cn.lili.modules.store.entity.dto;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.security.enums.SceneEnums;
import cn.lili.modules.store.entity.enums.StoreStatusEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * 店铺搜索参数VO
 *
 * @author pikachu
 * @since 2020-03-07 17:02:05
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class StoreSearchParams implements Serializable {

    @Serial
    private static final long serialVersionUID = 6916054310764833369L;


    @ApiModelProperty(value = "店铺id集合")
    private List<String> storeIds;

    @ApiModelProperty(value = "店铺名称")
    private String storeName;
    /**
     * @see StoreStatusEnum
     */
    @ApiModelProperty(value = "店铺状态")
    private String storeStatus;

    @ApiModelProperty(value = "开始时间")
    private String startDate;

    @ApiModelProperty(value = "结束时间")
    private String endDate;


    @ApiModelProperty(value = "保留字段1", hidden = true)
    private String field1;

    @ApiModelProperty(value = "保留字段2", hidden = true)
    private String field2;

    @ApiModelProperty(value = "保留字段3", hidden = true)
    private String field3;

    @ApiModelProperty(value = "保留字段4", hidden = true)
    private String field4;

    @ApiModelProperty(value = "保留字段5", hidden = true)
    private String field5;

    @ApiModelProperty(value = "场景", hidden = true)
    private String scene;

    @ApiModelProperty(value = "法人姓名")
    private String legalPerson;

    @ApiModelProperty(value = "用户id")
    private String userId;

    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        if (CollUtil.isNotEmpty(storeIds)) {
            queryWrapper.in("id", storeIds);
        }
        if (CharSequenceUtil.isNotEmpty(storeName)) {
            queryWrapper.like("store_name", storeName);
        }
        if (CharSequenceUtil.isNotEmpty(storeStatus)) {
            queryWrapper.eq("store_status", storeStatus);
        }
        //按时间查询
        if (CharSequenceUtil.isNotEmpty(startDate)) {
            queryWrapper.ge("create_time", DateUtil.parse(startDate));
        }
        if (CharSequenceUtil.isNotEmpty(endDate)) {
            queryWrapper.le("create_time", DateUtil.parse(endDate));
        }

        if (CharSequenceUtil.isNotEmpty(field1)) {
            queryWrapper.eq("field1", field1);
        }
        if (CharSequenceUtil.isNotEmpty(field2)) {
            queryWrapper.eq("field2", field2);
        }
        if (CharSequenceUtil.isNotEmpty(field3)) {
            queryWrapper.eq("field3", field3);
        }
        if (CharSequenceUtil.isNotEmpty(field4)) {
            queryWrapper.eq("field4", field4);
        }
        if (CharSequenceUtil.isNotEmpty(field5)) {
            queryWrapper.eq("field5", field5);
        }
        if (CharSequenceUtil.isNotEmpty(scene)) {
            queryWrapper.eq("scene", SceneEnums.getScene(scene).name());
        }
        if (CharSequenceUtil.isNotEmpty(legalPerson)) {
            queryWrapper.like("legal_person", legalPerson);
        }
        if (CharSequenceUtil.isNotEmpty(userId)) {
            queryWrapper.eq("enter_id", userId);
        }
        return queryWrapper;
    }
}
